import { Controller, GET, AbstractController } from 'fastify-decorators'
import { FastifyReply } from 'fastify'

@Controller({ route: '/' })
export default class AppController extends AbstractController {
  @GET({ url: '/' })
  async indexAction(request, reply: FastifyReply<any>) {
    const plugins = this.instance.plugins()

    if (!plugins.length) {
      reply.callNotFound()
    }

    const [{ pluginPath }] = plugins
    reply.redirect(`/plugins/${pluginPath}`)
  }
}
